//
//  BC_Zoo.h
//  CocOth
//
//  Created by BrunoCausse on 17/12/10.
//  Copyright 2010-2013 poulailler cie. All rights reserved.
//

#import <Cocoa/Cocoa.h>



@class BC_ZooRequest;
@class CocOthAppController;

@class BC_Board;
@class BC_Hashtable;

@interface BC_Zoo : NSObject
#if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5)
<NSStreamDelegate>
#endif
{
	
	CocOthAppController *appController;
	
	NSMutableData	*_data;
		
	NSTimer			*keepAlive;
	NSTimer			*observerConnectTimer;
	
	NSInputStream	*iStream;
	BOOL			iStreamCompletedOpen;
	NSOutputStream	*oStream;
	BOOL			oStreamCompletedOpen;
	
	NSUInteger		asker;
	
	NSMutableArray	*requests;
	volatile int	nRequests;
	
	NSLock			*IO_sync;
	volatile int	 abort;
	
	unsigned int	 limit_leaf;
	
	BOOL search_should_use_variable_leaf_horizon; 
	BOOL search_should_use_selectivity;
	BOOL search_should_use_accurate_ordering;
	BOOL search_should_use_conservative_YBWC;
	BOOL search_should_use_speculative_YBWC;
	
//	NSThread		*threadMain;
		
	NSLock			*createThreadLock;
	volatile int	 nThreads;
    
    BC_Hashtable    *hashtable;
    
    NSMutableDictionary *options;

}

@property (readonly) NSUInteger asker;
@property (readonly) volatile int nRequests;

- (id)initWithAppController:(CocOthAppController *)controller;

- (void)invalidate;
- (void)disconnect;

- (void)aborting;

- (void)add:(BC_ZooRequest *)aResquest;

- (void)search:(BC_Board *)aBoard;
- (void)startScript:(NSURL *)url;

// delegate method
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode;

//debug
- (void)listeRequests;


@end
